package pattern;

/*
 * @author changfei
 * @date  2023/11/28 11:38
 * @description 懒汉式
 */
public class LazySingleton {

    private static volatile LazySingleton lazySingleton;

    private LazySingleton() {
    }

    /**
     * double check lock DCL
     *
     * @return
     */
    public static LazySingleton getInstance() {
        if (lazySingleton == null) {
            synchronized (LazySingleton.class) {
                if (lazySingleton == null) {
                    return new LazySingleton();
                }
            }
        }

        return lazySingleton;
    }
}
